#ifndef BORNEDNUMBER_H_
#define BORNEDNUMBER_H_

template<typename T> 
class BornedNumber
{
	protected :
	T max__;
	T min__;
	T value__;

	void minmaxCheck()
	{
		if (max__ < min__)
		{
			T tmp = min__;
			min__ = max__;
			max__ = tmp;
		}
	}

	void check()
	{
		if (value__ > max__)
			value__ = max__;
		else if (value__ < min__)
			value__ = min__;
	}

	public:
	BornedNumber(T value=0, T max=100, T min=0)
	{
		max__ = max;
		min__ = min;
		value__ = value;
		minmaxCheck();
		check();
	}

	BornedNumber(const BornedNumber<T>& b)
	{
		min__ = b.min__;
		max__ = b.max__;
		value__ = b.value__;
	}

	T getMax() { return max__; }
	T getMin() { return min__; }
	T getValue(){ return value__; }
	void setMax(T m) { max__ = m; minmaxCheck(); check(); }
	void setMin(T m) { min__ = m; minmaxCheck(); check(); }

	BornedNumber<T>& operator=(T v)
	{
		value__ = v;
		check();
		return *this;
	}

	BornedNumber<T>& operator=(const BornedNumber<T>& v)
	{
		min__ = v.min__;
		max__ = v.max__;
		value__ = v.value__;

		return *this;
	}

	operator T()
	{
		return value__;
	}

	T operator()()
	{
		return value__;
	}

	BornedNumber<T>& operator+=(T v)
	{
		value__ += v;
		check();
		return *this;
	}

	BornedNumber<T>& operator+=(const BornedNumber<T>& v)
	{
		return *this += v.value__;
	}

	BornedNumber<T>& operator-=(T v)
	{
		value__ -= v;
		check();
		return *this;
	}

	BornedNumber<T>& operator-=(const BornedNumber<T>& v)
	{
		return *this -= v.value__;
	}
	
	BornedNumber<T>& operator*=(T v)
	{
		value__ *= v;
		check();
		return *this;
	}

	BornedNumber<T>& operator*=(const BornedNumber<T>& v)
	{
		return *this *= v.value__;
	}

	BornedNumber<T>& operator/=(T v)
	{
		value__ /= v;
		check();
		return *this;
	}

	BornedNumber<T>& operator/=(const BornedNumber<T>& v)
	{
		return *this /= v.value__;
	}


	bool operator==(T v)
	{
		return value__ == v;
	}

	bool operator==(const BornedNumber<T>& v)
	{
		return value__ == v.value__;
	}

	bool operator!=(T v)
	{
		return value__ != v;
	}

	bool operator!=(const BornedNumber<T>& v)
	{
		return value__ != v.value__;
	}

	bool operator<(T v)
	{
		return value__ < v;
	}

	bool operator<(const BornedNumber<T>& v)
	{
		return value__ < v.value__;
	}

	bool operator<=(T v)
	{
		return value__ <= v;
	}

	bool operator<=(const BornedNumber<T>& v)
	{
		return value__ <= v.value__;
	}

	bool operator>(T v)
	{
		return value__ > v;
	}

	bool operator>(const BornedNumber<T>& v)
	{
		return value__ > v.value__;
	}

	bool operator>=(T v)
	{
		return value__ >= v;
	}

	bool operator>=(const BornedNumber<T>& v)
	{
		return value__ >= v.value__;
	}
};

#endif

